package com.net.xpay.common.manager.impl.stat;

import com.google.common.base.Preconditions;
import com.net.xpay.common.manager.stat.UserRealTimeStatManager;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.stat.UserRealTimeStatMapper;
import com.net.xpay.common.domain.stat.UserRealTimeStat;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.model.AggUserDailyStatModel;
import com.net.xpay.core.model.UserDailyStatSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class UserRealTimeStatManagerImpl extends AbstractManager<UserRealTimeStat> implements UserRealTimeStatManager {

    @Autowired
    private UserRealTimeStatMapper mapper;


    @Override
    protected BasicMapper<Long, UserRealTimeStat> getMapper() {
        return mapper;
    }

    @Override
    public UserRealTimeStat getByUserId(Long userId) {
        UserRealTimeStat condition = new UserRealTimeStat();
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public List<AggUserDailyStatModel> aggSearch(UserDailyStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("user_id", "desc");
        return mapper.aggSearch(searchModel, page) == null ? new ArrayList<>() : mapper.aggSearch(searchModel, page);
    }

    @Override
    public long aggSearchCount(UserDailyStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.aggSearchCount(searchModel);
    }
}
